﻿using System;
using System.Globalization;
using System.Threading;
using System.Web.Mvc;

namespace Gama.Website.Controllers
{
    public abstract class BaseController : Controller
    {
        //protected override void OnActionExecuted(ActionExecutedContext filterContext)
        //{
        //    ViewResultBase view = filterContext.Result as ViewResultBase;
        //}
        protected override void ExecuteCore()
        {
            var lang = RouteData.Values["lang"] == null ? VisitContext.Cookie.Language : RouteData.Values["lang"].ToString();
            
            if (lang != VisitContext.Cookie.Language)
            {
            VisitContext.Cookie.Language = lang;
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
            }
            base.ExecuteCore();
        }        
    }
}